Page({
  data: {
    formData: {
      start: '',
      end: '',
    },
    isSubmitEnable: false
  },
  onLoad: function (options) {
    wx.hideShareMenu();
    this.initData(options)
  },
  initData: function ({ start, end }) {
    start = start || ''
    end = end || ''
    this.updateRange({ start, end })
  },
  updateRange: function (payload) {
    this.setData({
      formData: { ...this.data.formData, ...payload }
    }, this.checkCanSubmit)
  },
  //开始时间
  onBeginChange: function (e) {
    const start = e.detail.value
    this.updateRange({ start })
  },

  //结束时间
  onEndChange: function (e) {
    const end = e.detail.value
    this.updateRange({ end })
  },

  //点击确定
  onSure: function () {
    //调用方法，返回上一页
    const pages = getCurrentPages();
    const prePage = pages[pages.length - 2];
    prePage.updateTimeRange(this.data.formData);
    //返回
    wx.navigateBack({});
  },
  checkCanSubmit: function () {
    const { start, end } = this.data.formData
    let isSubmitEnable = false
    if (start && end) {
      isSubmitEnable = true
    } else {
      isSubmitEnable = false
    }
    this.setData({
      isSubmitEnable
    })
    return isSubmitEnable
  },
})